<template>
  <el-dialog :title="isEdit?'分销员审核':'申请详情'" width="1000px" :visible.sync="show" :append-to-body="true" :before-close="beforeClose">
    <el-form :inline="true" :model="searchForm" label-width="100px">
      <el-form-item label="用户ID">
        <el-input v-model="detailForm.user_id" class="border_input" disabled  ></el-input>
      </el-form-item>
      <el-form-item label="授权手机号">
        <el-input :value="detailForm.user_phone?detailForm.user_phone:'----'" disabled  ></el-input>
      </el-form-item>
      <el-form-item label="昵称">
        <el-input v-model="detailForm.nickName" disabled  ></el-input>
      </el-form-item>
      <el-form-item label="姓名">
        <el-input v-model="detailForm.true_name" disabled  ></el-input>
      </el-form-item>
      <el-form-item label="手机号">
        <el-input v-model="detailForm.phone" disabled  ></el-input>
      </el-form-item>
      <el-form-item label="申请时间">
        <el-input :value="detailForm.create_time | handleTime(1)" disabled></el-input>
      </el-form-item>
      <el-form-item label="备注">
        <el-input type="textarea" v-model="detailForm.content" style="width:490px;" disabled  ></el-input>
      </el-form-item>
    </el-form>
    <el-divider></el-divider>
    <div v-if="!isEdit">
      <el-form :inline="true" :model="searchForm" label-width="100px">

        <el-form-item label="处理时间">
          <el-input  v-if="detailForm.update_time" :value="detailForm.update_time | handleTime(1)" disabled style="width:200px"  ></el-input>
          <el-input  v-else disabled style="width:200px"></el-input>
        </el-form-item>
        <el-form-item label="审核结果">
          <el-input value="通过" v-if="detailForm.status==1" disabled  ></el-input>
          <el-input value="待审核" v-if="detailForm.status==0" disabled  ></el-input>
          <el-input value="驳回" v-if="detailForm.status==-1" disabled  ></el-input>
        </el-form-item>
        <el-form-item label="审核意见">
          <el-input type="textarea" style="width:490px;" v-model="detailForm.auditOpinion" disabled  ></el-input>
        </el-form-item>
      </el-form>
    </div>
    <div style="width:100%" v-else>
      <el-form :inline="true" :model="searchForm" label-width="100px">
        <el-form-item label="审核状态" prop="is_distribution">
          <el-radio-group v-model="sumForm.status">
            <el-radio :label="1">通过</el-radio>
            <el-radio :label="-1">驳回</el-radio>
          </el-radio-group>
        </el-form-item>
        </el-form>
        <el-form :inline="true" :model="searchForm" label-width="100px">
        <el-form-item label="审核意见">
        <el-col :span="24">
        <el-input
            type="textarea"
            placeholder="请输入内容"
            v-model="sumForm.auditOpinion"
            maxlength="300"
            style="width:550px;height:100px"
            show-word-limit
          ></el-input></el-col>
        </el-form-item>
      </el-form>
    </div>
    <el-divider></el-divider>
    <div class="btn_view">
      <el-button size="small" type="primary" @click="show=false" plain>取消</el-button>
      <el-button size="small" type="primary" @click="subMit">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  props: {
    showMember: false,
    showEdit: false,
    showMemberId: ''
  },
  data () {
    return {
      searchForm: {
        name: ''
      },
      memberId: '',
      isEdit: false,
      detailForm: {
        user_id: '',
        true_name: '',
        phone: '',
        status: '',
        create_time: '',
        nickName: '',
        content: ''

      },
      sumForm: {
        status: 1,
        auditOpinion: '',
        id: ''
      },
      show: false,
      val: this.value,
      coreWidth: this.width,
      isDisabled: this.disabled,
      currentIndex: this.$store.state.operate.currentIndex
    }
  },
  watch: {
    showMemberId (val) {
      this.sumForm.id = val
      this.memberId = val
    },
    showEdit (val) {
      this.isEdit = val
    },
    showMember (val) {
      this.show = true
      this.getMemberDetail()
    }
  },
  filters: {
    handleTime (val, type) {
      let time = type === 1 ? moment(val * 1000).format('YYYY-MM-DD') : type === 2 ? moment(val * 1000).format('HH:mm:ss') : moment(val * 1000).format('YYYY-MM-DD HH:mm:ss')
      return time
    }
  },
  methods: {
    beforeClose () {
      this.sumForm.auditOpinion = ''
      this.show = false
    },
    subMit () {
      if (this.isEdit) {
        // if (this.sumForm.auditOpinion.trim().length === 0) {
        //   return this.$message.warning('请输入审核意见')
        // }
        this.$api.updateExDistributor(this.sumForm).then(res => {
          this.$message.success('提交成功')
          this.show = false
          this.$emit('changeMember')
        })
      }
    },
    getMemberDetail () {
      this.$api.getGetDistributorInfo({
        id: this.memberId
      }).then(res => {
        this.detailForm = res.data
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.btn_view {
  height: 60px;
  width: 100%;
  text-align: center;
  background: #ffffff;
  line-height: 60px;
}
.border_input{
    border: none;
    background: #ffffff;
}
</style>
